/**
 * Created by xiaowenzi on 2018/6/6.
 */
//1.鼠标hover四个li,右边对应切换四个图片
//2.将图片路径放入一个数组中
$(function () {
    $('.currentYear').text(new Date().getFullYear());
    function imgChange() {
        $('.box .menus li').each(function() {
            $('.box .menus  li').mouseover(function(){
                $(this).addClass('active').siblings().removeClass('active');
                var i =$(this).index();
                $('.right .scroll').css('margin-top',-i*350+'px');
            })
        })
    }
    imgChange();

    //上传图纸报价
    function update() {
        // $(' .quotation1').click(function () {
        //     window.open('/quote.html');
        //     //window.open('/service/3dp.html');
        //     //window.open('https://www.pineprint.com/service/3dp.html');
        // });
        $(' .quotation2').click(function () {
            window.open('/client/order/order-fast');
        });
        //点击立即下单,要判断客户当前是否是登录状态
        //如果没有登录,链接跳转到登录注册页
        //如果已经登录,跳转后台主页
    }

    update();

    //最新动态的滚动效果
    //1.随机生成一个时间值  //成功注册(随机生成一个1-59之间的数字)
    //2.随机生成一个姓氏
    //3.用字符串拼接方式去写
    //4.用RegExp
    //4.让它展示为滚动状态

    var surname = ["赵", "钱", "孙", "李", "周", "吴", "郑", "王",
            "冯", "陈", "褚", "卫", "蒋", "沈", "韩", "杨",
            "朱", "秦", "尤", "许", "何", "吕", "施", "张",
            "孔", "曹", "严", "华", "金", "魏", "陶", "姜",
            "戚", "谢", "邹", "喻", "柏", "水", "窦", "章",
            "云", "苏", "潘", "葛", "奚", "范", "彭", "郎",
            "鲁", "韦", "昌", "马", "苗", "凤", "花", "方",
            "俞", "任", "袁", "柳", "酆", "鲍", "史", "唐",
            "费", "廉", "岑", "薛", "雷", "贺", "倪", "汤"],
        // speed = 5,
        timer,
        main = $('trendstListId');
    $(function () {
        var liHight = $('li').height();
    })
    //获取八个案例的图片
    $(document).ready(function () {
        var strUrl = window.location.href;
        // if(strUrl.indexOf("/solution")!=-1){
        //     loadSolution(strUrl);
        // }
        if(strUrl.indexOf("/html/price")!=-1){
            loadMaterial(strUrl);
        }
    });

    function loadMaterial(strUrl) {
        var arrUrl = strUrl.split("/");
        var x = arrUrl[arrUrl.length - 1].split(".");
        var strPage = x[0];
        var caseType;
        switch (strPage) {
            case 'jinshu-1mjg':
                caseType = 'DIESTEEL';
                break;
            case 'jinshu-2bxg':
                caseType = 'STAINLESSSTEEL';
                break;
            case 'jinshu-3thj':
                caseType = 'TITANIUMALLOY';
                break;
            case 'nilong-1gc':
                caseType = 'GCNL';
                break;
            case 'nilong-2jk':
                caseType = 'JKNL';
                break;
            case 'nilong-3bx':
                caseType = 'NLBX';
                break;
            case 'shuzhi-1gmsz':
                caseType = 'GMSZ';
                break;
            case 'shuzhi-2tmsz':
                caseType = 'TMSZ';
                break;
            case 'shuzhi-3btmsz':
                caseType = 'BTMSZ';
                break;
            case 'shuzhi-4ngwsz':
                caseType = 'NGWSZ';
                break;
            case 'shuzhi-5gqdsz':
                caseType = 'GJDGRXSZ';
                break;
            default:
                return;
        }

        $.ajax({
            url: "/case/getEightCases2",
            type: 'POST',
            data: "itemKey=" + caseType,
            success: function (caseList) {
                if (caseList.length > 0) {
                    var x = document.getElementsByName("myImage");
                    var y = document.getElementsByName("myImageP");
                    for (var i = 0; i < caseList.length; i++) {
                        if (caseList[i].thumbnailUrl.length != 0){
                            x[i].src = caseList[i].thumbnailUrl;
                            x[i].style.cursor="pointer";
                            x[i].id = caseList[i].id;
                            x[i].onclick = function(){
                                window.open("/case/"+this.id+".html");
                            }
                            y[i].innerHTML = caseList[i].title;
                        }
                    }
                }
            },
            error: function (e) {
                alert("加载案例失败");
            }
        })
    }
    
    function loadSolution(strUrl) {
        var arrUrl = strUrl.split("/");
        var x = arrUrl[arrUrl.length - 1].split(".");
        var strPage = x[0];
        var caseType;
        switch (strPage) {
            case 'one-trophy':
                caseType = 'CREATIVETROPHY';
                break;
            case 'two-machine':
                caseType = 'MACHINERYEQUIPMENT';
                break;
            case 'three-sandtable':
                caseType = 'YXSPJZ';
                break;
            case 'four-modeling':
                caseType = 'ZSMJYXSLXQ';
                break;
            case 'five-plam':
                caseType = '3DDYSB';
                break;
            case 'six-robot':
                caseType = 'JQRWKDY';
                break;
            case 'seven-car':
                caseType = 'QCYFSB';
                break;
            case 'eight-small':
                caseType = 'XPLZZ';
                break;
            default:
                return;
        }

        $.ajax({
            url: "/case/getEightCases",
            type: 'POST',
            data: "caseType=" + caseType,
            success: function (caseList) {
                if(caseType == "ZSMJYXSLXQ"){
                    return false;
                }
                if (caseList.length > 0) {
                    var x = document.getElementsByName("myImage");
                    var y = document.getElementsByName("myImageP");
                    for (var i = 0; i < caseList.length; i++) {
                        if (caseList[i].thumbnailUrl.length != 0){
                            x[i].src = caseList[i].thumbnailUrl;
                            x[i].style.cursor="pointer";
                            x[i].id = caseList[i].id;
                            x[i].onclick = function(){
                                window.open("/case/"+this.id+".html");
                            }
                            y[i].innerHTML = caseList[i].title;
                        }
                    }
                }
            },
            error: function (e) {
                alert("加载案例失败");
            }
        })
    }

});

